


  function getSearchParams() {
    return location.search.slice(1).split('&').reduce(function(prev, cur) {
        var cs = cur.split('=');
        if (!cs[0]) return prev;
        var data = {};
        data[cs[0]] = decodeURIComponent(cs[1]);
        return Object.assign(prev, data)
    }, {})
  }

window.onload = function() {
    wx.miniProgram.getEnv(function(res) {
        var query = getSearchParams();
        var code = query.code;
        console.log(code);
        if (res.miniprogram) {
          wx.miniProgram.postMessage({ data: { code } });
          setTimeout(function() {
            wx.miniProgram.navigateBack();
          }, 0);
        } else {
          window.postMessage({ data: { code } }, '*');
        }
      });
}
  